package com.cloudkinto.appletController.orderback;

import com.cloudkinto.appletservice.orderback.AppletOrderBackService;
import com.cloudkinto.appletservice.orderback.vo.AppletOrderBackPageRes;
import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.controller.orderback.OrderBackController;
import com.cloudkinto.service.orderback.vo.OrderBackCustomerProcessingReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Author Administrator
 *
 * @Des
 * @Version
 * @Date 2020/11/24
 */
@RestController
@Api(tags = "小程序退货截单模块")
@RequestMapping("/api/applet/orderBack")
public class AppletOrderBackController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(OrderBackController.class);

    @Autowired
    private AppletOrderBackService service;

    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查看详情", notes = "根据id查看详情")
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", service.detail(id));
    }

//    @UserSessionRequired
//    @GetMapping("/pageInit")
//    @ApiOperation(value = "查询初始化", notes = "查询初始化")
//    public SingleResult pageInit() {
//        return service.pageInit(getShopId(),getCompanyId(),getCurrentUserId());
//    }

//    @GetMapping("/list")
//    @ApiOperation(value = "查询", notes = "查询")
//    public SingleResult list(HttpServletRequest request){
//        Long companyId = getCompanyId();
//
//        Map<String, String> map = new HashMap<>();
//        String keyword = request.getParameter("keyword");
//        map.put("keyword", keyword);
//        return SingleResult.success("查询成功", service.getList(map));
//    }

    @UserSessionRequired
    @GetMapping("/listPage")
    @ApiOperation(value = "查询（分页）", notes = "查询（分页）")
    @ApiResponses({@ApiResponse(code = 200, message = "", response = AppletOrderBackPageRes.class)})
    public PageResult listPage(HttpServletRequest request) {
        Long companyId = getCompanyId();

        Map<String, String> map = new HashMap<>();
        String keyword = request.getParameter("keyword");
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        String status = request.getParameter("status");
        String result = request.getParameter("result");
        map.put("keyword", keyword);
        map.put("current", current);
        map.put("status", status);
        map.put("result", result);
        if (getShopId() != null)
            map.put("shopId", getShopId() + "");
        map.put("pageSize", size);
        map.put("companyId", companyId + "");
        return service.getListPage(map);
    }

    @UserSessionRequired
    @PostMapping("/customerProcessing")
    @ApiOperation(value = "顾客处理", notes = "顾客处理")
    public SingleResult customerProcessing(@RequestBody @Validated OrderBackCustomerProcessingReq req) {
        Long userId = getCurrentUserId();
        Long companyId = getCompanyId();
        service.customerProcessing(req, userId, companyId);
        return SingleResult.success();
    }

}
